package dynamicJsonVerifyer.verifyers;

import com.alibaba.fastjson.JSONObject;
import dynamicJsonVerifyer.FieldVerifyer;
import dynamicJsonVerifyer.Const.*;

import java.util.Map;

public abstract class JudgeNullVerifyer implements FieldVerifyer {

    public boolean verify(JSONObject verifyMetadata, Object appointVaildData) {

        if(appointVaildData==null){

            /**
             * true, 能为空且为空，则跳过校验
             * false, 能为空但又为空，则校验不通过
             */

            if(verifyMetadata.get(VaildMetadataItem.canNull)!=null){
                return verifyMetadata.getInteger(VaildMetadataItem.canNull) == 1;
            }

            /**
             * TODO 是否应该加个默认，return false;
             */
        }

        return verifyAny(verifyMetadata, appointVaildData);
    }

    protected abstract boolean verifyAny(JSONObject verifyMetadata, Object appointVaildData);


}
